package com.example.hotel.ease.web;

import com.example.hotel.ease.ex.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(ServiceException.class)
    public JsonResult handleServiceException(ServiceException e) {
        log.error("捕获到运行时异常: {}", e.getMessage());
        return JsonResult.fail(e.getCode(), e.getMessage());
    }
}